# -*- coding: utf-8 -*-

from .img import *


class Png(Img):
    __FORMAT__ = 'png'
    __MAGIC__ = bytearray(b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a')

    @classmethod
    def size(cls, fobj):
        rb = fobj.read(24)
        w = int.from_bytes(rb[-8:-4], byteorder='big')
        h = int.from_bytes(rb[-4:], byteorder='big')

        return ImgSize(fobj.file_size, w, h)
